package com.ruoyi.purchase.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.domain.QualityInfo;
import com.ruoyi.purchase.service.IQualityInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * qualityInfoController
 * 
 * @author kevinness
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/qualityInfo")
public class QualityInfoController extends BaseController
{
    @Autowired
    private IQualityInfoService qualityInfoService;

    /**
     * 查询qualityInfo列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QualityInfo qualityInfo)
    {
        startPage();
        List<QualityInfo> list = qualityInfoService.selectQualityInfoList(qualityInfo);
        return getDataTable(list);
    }

    /**
     * 通过订单编号获取质检信息列表
     */
    @PostMapping("/orderNo")
    public AjaxResult getQualityInfosByOrderNo(@RequestBody String orderNo){
        QualityInfo qualityInfo = new QualityInfo();
        qualityInfo.setOrderNo(orderNo);
        return success(qualityInfoService.selectQualityInfoList(qualityInfo));
    }

    /**
     * 导出qualityInfo列表
     */
    @Log(title = "qualityInfo", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityInfo qualityInfo)
    {
        List<QualityInfo> list = qualityInfoService.selectQualityInfoList(qualityInfo);
        ExcelUtil<QualityInfo> util = new ExcelUtil<QualityInfo>(QualityInfo.class);
        util.exportExcel(response, list, "qualityInfo数据");
    }

    /**
     * 获取qualityInfo详细信息
     */
    @GetMapping(value = "/{inspectionNo}")
    public AjaxResult getInfo(@PathVariable("inspectionNo") String inspectionNo)
    {
        return success(qualityInfoService.selectQualityInfoByInspectionNo(inspectionNo));
    }

    /**
     * 新增qualityInfo
     */
    @Log(title = "qualityInfo", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityInfo qualityInfo)
    {
        return toAjax(qualityInfoService.insertQualityInfo(qualityInfo));
    }

    /**
     * 修改qualityInfo
     */
    @Log(title = "qualityInfo", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityInfo qualityInfo)
    {
        return toAjax(qualityInfoService.updateQualityInfo(qualityInfo));
    }

    /**
     * 删除qualityInfo
     */
    @Log(title = "qualityInfo", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectionNos}")
    public AjaxResult remove(@PathVariable String[] inspectionNos)
    {
        return toAjax(qualityInfoService.deleteQualityInfoByInspectionNos(inspectionNos));
    }
}
